home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17600 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: prof.ese-metz.fr!news
  2. From: Dominique.Pelle@ingenieurs.supelec.fr (Dominique PELLE)
  3. Newsgroups: comp.lang.c++
  4. Subject: template question
  5. Date: Wed, 17 Apr 1996 03:17:06 GMT
  6. Organization: Supelec Metz
  7. Message-ID: <4l0mk7$4n0@prof.ese-metz.fr>
  8. NNTP-Posting-Host: netrider-port2.supelec.fr
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Hello c++ gurus, 
  12.  
  13. I have a simple problem to solve: 
  14.  
  15. I would like to have an integer type on n bits and I would like 
  16. to overload operator+ so that I can use it this way :
  17.  
  18.  
  19.   integer<7> variable_7bits = 125;
  20.   integer<4> variable_4bits = 15;
  21.   integer<7> variable_7bits;
  22.  
  23.   variable_7bits = variable_7bits + variable_4bits;
  24.  
  25.   // 'variable_7bits' is now equal to :
  26.   //  ->  125+15
  27.   //  ->  140
  28.   //  ->  12  (because it is on 7 bits)
  29.  
  30.  
  31.   
  32. No matter if it is coded on 32 bits, all it has to do, is perform
  33. operations so that it wraps around n bits AND ALSO detects if the
  34. operation overflows to warn the user.
  35.  
  36.  
  37. The question is :
  38. ~~~~~~~~~~~~~~~
  39.  
  40. ????????? HOW CAN I WRITE THE OPERATOR+ FUNCTION ??????????
  41.  
  42.  
  43. --
  44. ==== Dominique PELLE =================================================
  45. e-mail --> Dominique.Pelle@ingenieurs.supelec.fr          
  46. D. PELLE is Copyleft on IRC  &  Patator on FICS (chess.eerie.fr 5000)
  47. ==== Hidden DOS secret : add SET BUGS=OFF to your config.sys =========
  48.  
  49.  
  50.  
  51.    
  52.  
  53.